package com.blockchain.console.servlets.trading.xlb.cylj;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.IsPass;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.CyljEntity;
import com.blockchain.console.service.trading.query.CyljQuery;
import com.blockchain.console.servlets.trading.AbstractTradingServlet;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

@Right(id = "C_TRADING_UPDATECYLJ", name = "虚拟币管理-链接-编辑")
public class UpdateCylj extends AbstractTradingServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		CyljEntity x = tsradingManage.getCylj(id);
		request.setAttribute("x", x);
		forwardView(request, response, getClass());
	}

	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		int id = IntegerParser.parse(request.getParameter("id"));
		int bid = IntegerParser.parse(request.getParameter("bid"));
		CyljQuery c = new CyljQuery() {

			@Override
			public IsPass getXs() {
				return EnumParser.parse(IsPass.class, request.getParameter("xs"));
			}

			@Override
			public int getPx() {
				return IntegerParser.parse(request.getParameter("px"));
			}

			@Override
			public String getMc() {
				return request.getParameter("mc");
			}

			@Override
			public String getDz() {
				return request.getParameter("dz");
			}

			@Override
			public int getBid() {
				return IntegerParser.parse(request.getParameter("bid"));
			}


			@Override
			public IsPass getSfdxxs() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public String getNr() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public String getLinkNameOrParamEn() {
				return request.getParameter("linkNameEn");
			}

			@Override
			public String getLinkNameOrParamTw() {
				return request.getParameter("linkNameTw");
			}
		};

		tsradingManage.updateCylj(id, bid, c);
		String url = getController().getURI(request, CyljList.class) + "?bid=" + bid;
		sendRedirect(request, response, url);
	}

}
